<template>
  <div>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item>
        <div class="banner-img">
          <img src="@/assets/banner.png" alt="">
        </div>
        <div class="banner-text">台州市企业登记档案<br>自助查询平台</div>
      </van-swipe-item>
    </van-swipe>
    <a class="banner-tog" @click="togElder" v-if="showElder">老年模式</a>

    <van-dialog v-model="system.close || system.notice" title="提示" @confirm="closeNotice"
                :show-confirm-button="!system.close && system.notice">
      &nbsp;&nbsp;&nbsp;&nbsp;{{ system.message }} <br /><br />
    </van-dialog>
  </div>
</template>

<script>
import {getOldModal, setOldModal} from "@/utils/oldModal";
import {ajaxUtils, strUtils} from "@/utils/lwUtils";
import {getToken} from "@/utils/auth";
import {Dialog} from "vant";
import {apiGetStatus} from "@/api/eraqNotice";

export default {
  name: "topHeader",
  data() {
    return {
      elder: false,
      system: {close: false, notice: true, message: ""}
    }
  },
  props: {
    showElder: {
      type: Boolean, default: false,
    },
    authCheck: {
      type: Boolean, default: false,
    }
  },
  mounted() {
    //获取老年模式
    let oldModal = getOldModal();
    this.elder = strUtils.isEmpty(oldModal) ? false : oldModal !== "false";
    this.$emit("setElder", this.elder);
  },
  created() {
    this.getSystemStatus();
  },
  methods: {
    //切换适老化模式
    togElder() {
      this.elder = !this.elder;
      setOldModal(this.elder);
      this.$emit("setElder", this.elder);
    },
    getSystemStatus: function () {
      apiGetStatus().then(res => {
        if (ajaxUtils.isFail(res.code, res.msg)) {
          this.system = {close: false, notice: false, message: ""};
          return;
        }
        this.system = res.data;
        if (this.system.close || this.system.notice) {
          return;
        }
        //设置登录状态
        this.doSsoLogin();
      }).catch(() => {
        this.system = {close: false, notice: false, message: ""};
      });
    },
    doSsoLogin: function () {
      //若该页面不需要登录，则直接返回
      if (!this.authCheck) {
        return;
      }

      //检测URL是否有token参数——法人登录后返回
      //ssoUtil.checkUrlToken();

      let token = getToken();
      if (strUtils.isEmpty(token)) {
        this.$router.push({path: "/index", query: {errMsg: "登录超时"}});
      }
    },
    closeNotice: function () {
      if (!this.system.close && this.system.notice) {
        this.doSsoLogin();
      }
      this.system.close = false;
      this.system.notice = false;
    }

  }
}
</script>

<style lang='scss' scoped>
@import "src/css/home";
</style>
